﻿#ifndef ANDYRP_UNLIT_INCLUDED
#define ANDYRP_UNLIT_INCLUDED

#include "Util/Common.hlsl"


TEXTURE2D(_baseMap);
SAMPLER(sampler_baseMap);

UNITY_INSTANCING_BUFFER_START(UnityPerMaterial)
	UNITY_DEFINE_INSTANCED_PROP(float4, _baseColor)
	UNITY_DEFINE_INSTANCED_PROP(float4, _baseMap_ST)
	UNITY_DEFINE_INSTANCED_PROP(float, _Cutoff)
UNITY_INSTANCING_BUFFER_END(UnityPerMaterial)

struct Attribute
{
	UNITY_VERTEX_INPUT_INSTANCE_ID
	float3 positionOS:POSITION;
	float2 baseUV:TEXCOORD0;
	
};

struct Varyings{
	UNITY_VERTEX_INPUT_INSTANCE_ID
	float4 posCS:SV_POSITION;
	float2 baseUV : VAR_BASE_UV;
};

Varyings UnlitPassVertex(Attribute input)
{
	Varyings output;
	
    float3 posWS =	TransformObjectToWorld(input.positionOS);
	output.posCS = TransformObjectToHClip(posWS);
	float4 baseST = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial,_baseMap_ST);
	output.baseUV = input.baseUV * baseST.xy + baseST.zw;
	UNITY_SETUP_INSTANCE_ID(input);
	UNITY_TRANSFER_INSTANCE_ID(input, output);
    return output;
}


float4 UnlitPassFragment(Varyings input):SV_TARGET
{
	UNITY_SETUP_INSTANCE_ID(input);
	float4 baseMap = SAMPLE_TEXTURE2D(_baseMap, sampler_baseMap, input.baseUV);
	float4 baseColor = UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _baseColor);
	float4 base = baseMap * baseColor;
	clip(base.a - UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial,_Cutoff));
	return base;

}
#endif
